package com.changanw.jedis.redisqueue;

import com.changanw.jedis.Redis;


public class DelayMsgTest {
    public static void main(String[] args) {
        Redis redis = new Redis();
        redis.execute(jedis -> {
            //构造一个消息队列
            final DelayMsgQueue delayMsgQueue = new DelayMsgQueue(jedis, "changanw-delay-queue");
            //构造消息的生产者
            Thread producer = new Thread(){
                @Override
                public void run() {
                    for (int i = 0; i < 5; i++) {
                        delayMsgQueue.queue("www.changanw.com"+i);

                    }
                }
            };
            //构造一个消费者
            Thread customer = new Thread(){
                @Override
                public void run() {
                    delayMsgQueue.loop();
                }
            };
            //启动
            producer.start();
            customer.start();
            //休息7秒后停止程序
            try {
                Thread.sleep(7000);
                customer.interrupt();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
    }
}
